package io;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class PWDemo2 {
    public static void main(String[] args) throws FileNotFoundException {
        FileOutputStream fos=new FileOutputStream("pw2.txt");//不开追加模式就重头写
        OutputStreamWriter osw=new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        BufferedWriter bw=new BufferedWriter(osw);
        //PrintWriter pw=new PrintWriter(bw)//按行写出字符串，但是先存储于缓冲区，并非实时写出，要调用flush
        PrintWriter pw=new PrintWriter(bw,true);//构造器不同则效果不同，true自动换行刷新

       Scanner sc=new Scanner(System.in);
        String line;
        while (!"exit".equals((line)=sc.nextLine())) {

            pw.println(line);
        }
        sc.close();

        pw.println("嘿嘿");
        pw.println("哈哈");
        System.out.println("写出完毕");
        pw.close();

    }
}
